package com.controller;


import com.common.utils.PageUtils;
import com.common.utils.R;
import com.entity.ExamManageEntity;
import com.entity.FillQuestionEntity;
import com.entity.MultiQuestionEntity;
import com.service.*;
import com.vo.ExamManageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 考试管理表
 *
 * @author lxl
 * @email lixialang007@163.com
 * @date 2021-09-08 21:36:19
 */

@RestController
@RequestMapping("exam/exammanage")
public class ExamManageController {
    @Autowired
    private ExamManageService examManageService;


    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("exam:exammanage:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = examManageService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/createPaper")
    public R createPaper(@RequestBody ExamManageVO paper) {

        boolean res = examManageService.createPaper(paper.getPaperid(),paper.getSource());
        if (!res) {
            return R.error(paper.getSource()+ "的题库为空");
        }
        return R.ok();
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//   @RequiresPermissions("exam:exammanage:info")
    public R info(@PathVariable("id") Integer id) {
        ExamManageEntity examManage = examManageService.getById(id);

        return R.ok().put("examManage", examManage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//  @RequiresPermissions("exam:exammanage:save")
    public R save(@RequestBody ExamManageEntity examManage) {
        examManageService.save(examManage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("exam:exammanage:update")
    public R update(@RequestBody ExamManageEntity examManage) {
        examManageService.updateById(examManage);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("exam:exammanage:delete")
    public R delete(@RequestBody Integer[] ids) {
        examManageService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
